package com.probiz.estore.common.model.cart.base;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.probiz.estore.common.model.cart.Shoppingcart;
import com.probiz.estore.common.model.cart.ShoppingcartItem;
import com.probiz.estore.common.model.cart.ShoppingcartItemGc;
import com.probiz.estore.common.model.product.ProductSku;
import com.probiz.estore.common.model.sales.Gift;
import com.probiz.estore.core.model.BaseObject;

/**
 * ShoppingcartItem Base Java Bean, base class for the model, mapped directly to database table
 * 
 * Avoid changing this file if not necessary, will be overwritten.
 * 
 */
public class ShoppingcartItemTbl extends BaseObject implements Serializable {

	protected Integer shoppingcartItemId;
	
	// 指向一个单品
	protected ProductSku productSku;
	// 指向一个礼券
	private ShoppingcartItemGc shoppingcartItemGc;
	
	// 指向一个礼品
	protected Gift gift;
	/*
	 * 对应单品关联商品类型的kind 性质,决定是否可运输等 0=礼券 1=实体 2=服务 3=下载 4=点卡
	 */
	protected Short skuType;
	//原价
	protected BigDecimal price;
	//折扣价，是原价、批发价、折扣价中的其中一种
	protected BigDecimal discountPrice;
	//是否批发价
	protected Short isWholesale = ShoppingcartItem.ISWHOLESALE_NO;
	//是否特价
	protected Short isOnSale = ShoppingcartItem.ISONSALE_NO;
	//物品数量
	protected Integer quantity;
	//折扣的金额
	protected BigDecimal itemDiscountAmount = new BigDecimal(0);
	/**
	 * 物品类型
	 * 参考 Constants.ITEM_TYPE_PRODUCT，Constants.ITEM_TYPE_GC
	 */
	protected Short itemType;
	//指向购物车
	private Shoppingcart shoppingcart;
	protected Date addTime;
	//指向父，例如用于商品与商品维修服务等，暂无用，但保留
	protected ShoppingcartItem parent;
	//指向孩子(多个)，例如用于商品与商品维修服务等，暂无用，但保留
	protected Set<ShoppingcartItem> children = new HashSet<ShoppingcartItem>();

	/**
	 * Default Empty Constructor for class ShoppingcartItem
	 */
	public ShoppingcartItemTbl() {
		super();
		addTime = new Date();
	}

	/**
	 * Default Key Fields Constructor for class ShoppingcartItem
	 */
	public ShoppingcartItemTbl(Integer in_shoppingcartItemId) {
		this.setShoppingcartItemId(in_shoppingcartItemId);
		addTime = new Date();
	}

	/**
	 * *
	 * 
	 * @return Integer
	 * @hibernate.id column="shoppingcartItemId" type="java.lang.Integer" generator-class="native"
	 */
	public Integer getShoppingcartItemId() {
		return this.shoppingcartItemId;
	}

	/**
	 * Set the shoppingcartItemId
	 */
	public void setShoppingcartItemId(Integer aValue) {
		this.shoppingcartItemId = aValue;
	}

	public Short getSkuType() {
		return this.skuType;
	}

	public void setSkuType(Short aValue) {
		this.skuType = aValue;
	}

	/**
	 * *
	 * 
	 * @return java.math.BigDecimal
	 * @hibernate.property column="price" type="java.math.BigDecimal" length="12" not-null="true" unique="false"
	 */
	public java.math.BigDecimal getPrice() {
		return this.price;
	}

	/**
	 * Set the price
	 * 
	 * @spring.validator type="required"
	 */
	public void setPrice(java.math.BigDecimal aValue) {
		this.price = aValue;
	}

	/**
	 * *
	 * 
	 * @return java.math.BigDecimal
	 * @hibernate.property column="discountPrice" type="java.math.BigDecimal" length="12" not-null="false" unique="false"
	 */
	public java.math.BigDecimal getDiscountPrice() {
		return this.discountPrice;
	}

	/**
	 * Set the discountPrice
	 */
	public void setDiscountPrice(java.math.BigDecimal aValue) {
		this.discountPrice = aValue;
	}

	/**
	 * *
	 * 
	 * @return Integer
	 * @hibernate.property column="quantity" type="java.lang.Integer" length="10" not-null="true" unique="false"
	 */
	public Integer getQuantity() {
		return this.quantity;
	}

	/**
	 * Set the quantity
	 * 
	 * @spring.validator type="required"
	 */
	public void setQuantity(Integer aValue) {
		this.quantity = aValue;
	}

	/**
	 * *
	 * 
	 * @return java.math.BigDecimal
	 * @hibernate.property column="itemDiscountAmount" type="java.math.BigDecimal" length="12" not-null="false" unique="false"
	 */
	public java.math.BigDecimal getItemDiscountAmount() {
		return this.itemDiscountAmount;
	}

	/**
	 * Set the itemDiscountAmount
	 */
	public void setItemDiscountAmount(java.math.BigDecimal aValue) {
		this.itemDiscountAmount = aValue;
	}

	/**
	 * *
	 * 
	 * @return Short
	 * @hibernate.property column="isWholesale" type="java.lang.Short" length="5" not-null="true" unique="false"
	 */
	public Short getIsWholesale() {
		return this.isWholesale;
	}

	/**
	 * Set the isWholesale
	 * 
	 * @spring.validator type="required"
	 */
	public void setIsWholesale(Short aValue) {
		this.isWholesale = aValue;
	}

	/**
	 * *
	 * 
	 * @return Short
	 * @hibernate.property column="isOnSale" type="java.lang.Short" length="5" not-null="true" unique="false"
	 */
	public Short getIsOnSale() {
		return this.isOnSale;
	}

	/**
	 * Set the isOnSale
	 * 
	 * @spring.validator type="required"
	 */
	public void setIsOnSale(Short aValue) {
		this.isOnSale = aValue;
	}

	/**
	 * *
	 * 
	 * @return java.util.Date
	 * @hibernate.property column="addTime" type="java.util.Date" length="0" not-null="true" unique="false"
	 */
	public java.util.Date getAddTime() {
		return this.addTime;
	}

	/**
	 * Set the addTime
	 * 
	 * @spring.validator type="required"
	 */
	public void setAddTime(java.util.Date aValue) {
		this.addTime = aValue;
	}
	

	public ShoppingcartItem getParent() {
		return parent;
	}

	public void setParent(ShoppingcartItem parent) {
		this.parent = parent;
	}

	public Set<ShoppingcartItem> getChildren() {
		return children;
	}

	public void setChildren(Set<ShoppingcartItem> children) {
		this.children = children;
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof ShoppingcartItemTbl)) {
			return false;
		}
		ShoppingcartItemTbl rhs = (ShoppingcartItemTbl) object;
		return new EqualsBuilder().append(this.shoppingcartItemId, rhs.shoppingcartItemId).append(this.skuType, rhs.skuType).append(this.price, rhs.price)
				.append(this.discountPrice, rhs.discountPrice).append(this.quantity, rhs.quantity).append(this.itemDiscountAmount, rhs.itemDiscountAmount).append(this.isWholesale, rhs.isWholesale)
				.append(this.isOnSale, rhs.isOnSale).append(this.addTime, rhs.addTime).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		if (productSku != null) {
			return new HashCodeBuilder(-82280557, -700257973).append(productSku.getProductSkuCode()).append(skuType).append(addTime).toHashCode();
		}
		if (shoppingcartItemGc != null) {
			return new HashCodeBuilder(-82280557, -700257973).append(shoppingcartItemGc.getShoppingcartItemGcId()).toHashCode();
		}

		return new HashCodeBuilder(-82280557, -700257973).append(this.shoppingcartItemId).append(this.skuType).append(this.price).append(this.discountPrice).append(this.quantity).append(
				this.itemDiscountAmount).append(this.isWholesale).append(this.isOnSale).append(this.addTime).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("shoppingcartItemId", this.shoppingcartItemId).append("itemType", this.skuType).append("price", this.price).append("discountPrice", this.discountPrice)
				.append("quantity", this.quantity).append("itemDiscountAmount", this.itemDiscountAmount).append("isWholesale", this.isWholesale).append("isOnSale", this.isOnSale).append("addTime",
						this.addTime).toString();
	}

	/**
	 * Return the name of the first key column
	 */
	public String getFirstKeyColumnName() {
		return "shoppingcartItemId";
	}

	/**
	 * Return the Id (pk) of the entity, must be Integer
	 */
	public Integer getId() {
		return shoppingcartItemId;
	}

	public Shoppingcart getShoppingcart() {
		return shoppingcart;
	}

	public void setShoppingcart(Shoppingcart shoppingcart) {
		this.shoppingcart = shoppingcart;
	}

	public ProductSku getProductSku() {
		return productSku;
	}

	public void setProductSku(ProductSku productSku) {
		this.productSku = productSku;
	}

	public Short getItemType() {
		return itemType;
	}

	public void setItemType(Short itemType) {
		this.itemType = itemType;
	}

	public ShoppingcartItemGc getShoppingcartItemGc() {
		return shoppingcartItemGc;
	}

	public void setShoppingcartItemGc(ShoppingcartItemGc shoppingcartItemGc) {
		this.shoppingcartItemGc = shoppingcartItemGc;
	}

	public Gift getGift() {
		return gift;
	}

	public void setGift(Gift gift) {
		this.gift = gift;
	}
}